package com.netease.nim.demo.session.adapter;


import android.content.Context;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.ImageView;
import android.widget.TextView;

import com.shwread.android.qysw10000136.R;

import java.util.List;


public class MoreFunctionGridviewAdapter extends BaseAdapter {
	public interface onMoreFunctionItemClickListener {
		void onItemClick();
	}

	public static class MoreFunctionItemHolder {

		int resId;

		int stringId;

		public onMoreFunctionItemClickListener onItemClickListener;

		public MoreFunctionItemHolder(int resId, int stringId, onMoreFunctionItemClickListener onClickListener) {
			this.resId = resId;
			this.stringId = stringId;
			this.onItemClickListener = onClickListener;
		}
	}

	private Context context;

	private List<MoreFunctionItemHolder> moreFunctionItemHolders;

	public MoreFunctionGridviewAdapter(Context context, List<MoreFunctionItemHolder> moreFunctionItemHolders) {
		this.context = context;
		this.moreFunctionItemHolders = moreFunctionItemHolders;
	}

	@Override
	public int getCount() {
		return moreFunctionItemHolders.size();
	}

	@Override
	public Object getItem(int position) {
		return moreFunctionItemHolders.get(position);
	}

	@Override
	public long getItemId(int position) {
		return position;
	}

	@Override
	public View getView(int position, View convertView, ViewGroup parent) {
		View itemlayout;
		if (convertView == null) {
			itemlayout = LayoutInflater.from(context).inflate(R.layout.more_function_item_layout, null);
		} else {
			itemlayout = convertView;
		}

		MoreFunctionItemHolder viewHolder = moreFunctionItemHolders.get(position);
		((ImageView) itemlayout.findViewById(R.id.imageView)).setBackgroundResource(viewHolder.resId);
		((TextView) itemlayout.findViewById(R.id.textView)).setText(context.getString(viewHolder.stringId));
		return itemlayout;
	}
}

